from qfluentwidgets import (NavigationItemPosition, MessageBox, setTheme, Theme, MSFluentWindow,
                            NavigationAvatarWidget, qrouter, SubtitleLabel, setFont)
from qfluentwidgets import FluentIcon as FIF
from PyQt6.QtWidgets import QApplication, QFrame, QHBoxLayout
from PyQt6.QtGui import *
from PyQt6.QtCore import *

from pages.HomePage.homePage import HomePage


class Widget(QFrame):

    def __init__(self, text: str, parent=None):
        super().__init__(parent=parent)
        self.label = SubtitleLabel(text, self)
        self.hBoxLayout = QHBoxLayout(self)

        setFont(self.label, 24)
        self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.hBoxLayout.addWidget(self.label, 1, Qt.AlignmentFlag.AlignCenter)
        self.setObjectName(text.replace(' ', '-'))



class Window(MSFluentWindow):

    def __init__(self):
        super().__init__()

        # create sub interface
        # self.homeInterface = Widget('Home Interface', self)
        self.homeInterface = HomePage(self)
        self.appInterface = Widget('Application Interface', self)
        self.videoInterface = Widget('Video Interface', self)
        self.alarmInterface = Widget('alarm interface', self)
        self.chartInterface = Widget('chart Interface', self)
        self.checkInterface = Widget('check Interface', self)
        self.workStationInterface = Widget('workStation Interface', self)
        self.systemInterface = Widget('system Interface', self)
        self.msg = None

        self.initNavigation()
        self.initWindow()

    def initNavigation(self):
        self.addSubInterface(self.homeInterface, FIF.HOME, '首页', FIF.HOME_FILL)
        self.addSubInterface(self.appInterface, FIF.APPLICATION, '设备')
        self.addSubInterface(self.videoInterface, FIF.VIDEO, '预警')
        self.addSubInterface(self.alarmInterface, FIF.BRIGHTNESS, '报警')
        self.addSubInterface(self.chartInterface, FIF.BRIGHTNESS, '报表')
        self.addSubInterface(self.checkInterface, FIF.BRIGHTNESS, '巡检')
        self.addSubInterface(self.workStationInterface, FIF.BRIGHTNESS, '工作台')
        self.addSubInterface(self.systemInterface, FIF.CARE_DOWN_SOLID, '系统')

        self.navigationInterface.setCurrentItem(self.homeInterface.objectName())

    def initWindow(self):
        self.resize(900, 700)
        self.setWindowIcon(QIcon('static/image/home.png'))
        self.setWindowTitle('EHS智能监测预警工业软件平台')

    def closeEvent(self, event):
        self.msg = MessageBox("确定窗口", "是否确定关闭EHS程序", self)
        self.msg.yesButton.setText("确定")
        self.msg.cancelButton.setText("取消")
        if self.msg.exec():
            self.homeInterface.closeTime()
            event.accept()
        else:
            event.ignore()